import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import MyTable from "@/components/Table";
import mock from '@/mock/mock';

// 引入 ElementPlus
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import locale from 'element-plus/lib/locale/lang/zh-cn' //中文版本
// import * as ElIcons from '@element-plus/icons-vue' 
// for (const name in ElIcons) {
//   app.component(name, ElIcons[name])
// }

import { fn } from "@/utils/routerlist.js";
console.log('路由先走');
function loadRouter() {
  let token = localStorage.getItem('store');
  let menusList = JSON.parse(localStorage.getItem('menusList'));
  if (token && menusList) {
    let newList = fn(menusList)

    console.log('路由表结构', newList);
    newList.forEach(item => {
      router.addRoute("homeLayout", item)
      console.log(123)
    })
    console.log(2222)
  }
};
loadRouter()



/**
 * 时间格式化
 */
Date.prototype.format = function (fmt = 'yyyy-MM-dd HH:mm:ss') {
  /**
   * 日期数据
   */
  const opts = {
    'y+': this.getFullYear().toString(),
    'M+': (this.getMonth() + 1).toString(),
    'd+': this.getDate().toString(),
    'H+': this.getHours().toString(),
    'm+': this.getMinutes().toString(),
    's+': this.getSeconds().toString(),
    'f+': this.getMilliseconds().toString()
  }
  for (const key in opts) {
    const value = opts[key];  //时间值
    if (new RegExp(`(${key})`).test(fmt)) {
      const result = RegExp.$1; //如果匹配成功则可以获取到结果
      fmt = fmt.replace(result, value.padStart(result.length, '0'));
    }
  }
  return fmt;
}
//也可分开写
const app = createApp(App)
app.use(ElementPlus, { locale });
// app.use(Vant)
app.use(store)
app.use(router)
app.component("Table", MyTable)
// app.component("MySearch", MySearch)
app.mount('#app')

//全局图标引入
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component)
}

